package stripsPlanner;

import java.util.ArrayList;
import java.util.List;

import stripsLanguage.Ordering;
import stripsLanguage.Step;

public class BuildLinearizations {

	public BuildLinearizations() {}

	//TEST
	protected void buildLinearizations(
		List<List<Integer>> matrix,
		List<Integer> upToNowList,
		List<Step> steps,
		List<Ordering> orderings)
	{		
		for(int s = 0; s < steps.size(); ++s)
		{
			Step step = steps.get(s);
			boolean thisFree = true;
			List<Ordering> listOfOrderings = new ArrayList<Ordering>();
			for(int i = 0; i < orderings.size(); ++i)
			{	
				if(orderings.get(i).getLastStep().getId() == step.getId())				
				{
					thisFree = false;
					break;
				} else if(orderings.get(i).getFirstStep().getId() != step.getId())
					listOfOrderings.add(orderings.get(i));
			}
			if(thisFree)
			{
				List<Integer> newList = new ArrayList<Integer>();
				for(int i = 0; i < upToNowList.size(); i++)
					newList.add(upToNowList.get(i));
				newList.add(step.getId());
				if(steps.size() == 1)
				{
					newList.add(2);
					matrix.add(newList);
					return;
				}
				else
				{
					steps.remove(s);
					buildLinearizations(				
						matrix,
						newList,					
						steps,
						listOfOrderings);
					steps.add(s,step);
				}
			}
		}
	}
}
